package com.sun.audit.loader.impl;

import com.sun.audit.loader.EntitySnapshotLoader;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author pytho
 */
@Component
@Order(2)
public class MybatisSnapshotLoader implements EntitySnapshotLoader {

    @Autowired
    private SqlSessionTemplate sqlSession;

    @Override
    public Object load(Class<?> entityClass, Long entityId) {
        String statement = entityClass.getName() + "Mapper.selectById";
        return sqlSession.selectOne(statement, entityId);
    }
}
